﻿using Microsoft.Extensions.DependencyInjection;
using StartsEAS_API.BLL.Interfaces.IProfessionalB;
using StartsEAS_API.DAL.ProfessionalD;
using StartsEAS_API.Model;
using StartsEAS_API.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartsEAS_API.BLL.ProfessionalB
{
    public class ProfessionalBLL: IProfessionalBLL
    {
        private readonly StarsEASContext _context;
        public ProfessionalDAL _professionalDal;
        public ProfessionalBLL(IServiceScopeFactory context)
        {
            _context = context.CreateScope().ServiceProvider.GetRequiredService<StarsEASContext>();
            _professionalDal = new(_context);
        }

        public ResultUtils AddProfessional(string token, string professionalName,int CollegeId)
        {
            int result = _professionalDal.AddProfessional(token, professionalName,CollegeId);
            if (result == -1) return new ResultUtils() { code = 500, message = "您的输入有误或token有误" };
            return new ResultUtils() { code = 200, message = "操作成功" };
        }

        public ResultUtils GetAllProfessionals()
        {
            IEnumerable<Professional> professionals = _professionalDal.GetAllProfessionals();
            if (professionals == null) return new ResultUtils() { code = 500, message = "查询有误或为空" };
            return new ResultUtils() { code = 200, message = professionals };
        }

        public ResultUtils GetProfessionalById(int professionalId)
        {
            Professional professional = _professionalDal.GetProfessionalById(professionalId);
            if(professional==null) return new ResultUtils() { code = 500, message = "查询有误或为空" };
            return new ResultUtils() { code = 200, message = professional };
        }

        public ResultUtils GetProfessionalsByCollegeId(int CollegeId)
        {
            IEnumerable<Professional> professionals = _professionalDal.GetProfessionalsByCollegeId(CollegeId);
            if (professionals == null) return new ResultUtils() { code = 500, message = "未查询到专业信息" };
            return new ResultUtils() { code = 200, message = professionals };
        }

        public ResultUtils UpdateProfessional(string token, Professional data)
        {
            int result = _professionalDal.UpdateProfessional(token, data);
            if (result == -1) return new ResultUtils() { code = 500, message = "您的输入有误或token有误" };
            return new ResultUtils() { code = 200, message = "操作成功" };
        }
    }
}
